//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
//==================================================================

#ifndef GXY_BASE_H
#define GXY_BASE_H

#include "psys.h"
#include "pmatrix.h"
#include "rend_device.h"

//==================================================================
namespace GXY
{


//==================================================================
class Context;

//==================================================================
extern Context	*_ctxp;

//==================================================================
class Rect
{
public:
	float	_x, _y, _w, _h;

	Rect( float x, float y, float w, float h ): _x(x), _y(y), _w(w), _h(h)
	{
	}

	Rect(): _x(0), _y(0), _w(0), _h(0)
	{
	}

	void PositionInside( const Rect &outer_rect, int align_x=0, int align_y=0 )
	{
		if ( align_x < 0 )	_x = outer_rect._x;							else
		if ( align_x > 0 )	_x = outer_rect._x + outer_rect._w - _w;	else
							_x = outer_rect._x + (outer_rect._w - _w) * 0.5f;

		if ( align_y < 0 )	_y = outer_rect._y;							else
		if ( align_y > 0 )	_y = outer_rect._y + outer_rect._h - _h;	else
							_y = outer_rect._y + (outer_rect._h - _h) * 0.5f;
	}

	void Inset( float off_x, float off_y )
	{
		_x += off_x;
		_y += off_y;
		_w -= off_x*2;
		_h -= off_y*2;
	}
};

//==================================================================
Context *CreateContext( RendDevice *rdevicep, int disp_w, int disp_h, float disp_aspect );
void	SelectContext( Context *contextp );
RendDevice *GetRenderDevice();
void	PushState();
void	PopState();

//==================================================================
void	SetViewport( float x, float y, float w, float h );
void	GetViewport( float xywh[4]);

void	SetGlobalColorModulation( float r, float g, float b, float a );

int		GetDisplayWidth();
int		GetDisplayHeight();
float	GetDisplayAspect();

//==================================================================
};

#endif
